package com.yixia.pea.controller.gather;

/**
 * @author: 依梦
 * @Date 2023/10/1
 */

import com.yixia.common.core.controller.BaseController;
import com.yixia.common.core.domain.AjaxResult;
import com.yixia.common.core.domain.entity.SysUser;
import com.yixia.common.utils.StringUtils;
import com.yixia.common.utils.page.TableDataInfo;
import com.yixia.pea.domain.dto.SysUserDto;
import com.yixia.pea.domain.group.GatherUserGroup;
import com.yixia.pea.service.GatherGroupService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@ApiOperation("分组修改模块")
@Slf4j
@RestController
@RequestMapping("/gather/userGroup")
public class GatherUserGroupController extends BaseController {

    @Autowired
    private GatherGroupService groupService;

    // 获取没分配到该小组的用户信息
    @GetMapping("/unAllocatedList/{groupId}")
    public TableDataInfo unAllocatedList(@PathVariable Long groupId, SysUserDto userDto){
        startPageByHelper();// 分页查询
        List<SysUser> list = groupService.unAllocatedList(groupId, userDto);
        return getDataTable(list);
    }

    // 获取已经分配到该小组的用户信息
    @GetMapping("/allocatedList/{groupId}")
    public TableDataInfo allocatedList(@PathVariable Long groupId, SysUserDto userDto){
        startPageByHelper();// 分页查询
        List<SysUser> list = groupService.allocatedList(groupId);
        return getDataTable(list);
    }

    // 将用户添加到该小组
    @PostMapping("/addUserInGroup/{groupId}")
    public AjaxResult addUserInGroup(@PathVariable Long groupId, @RequestBody List<GatherUserGroup> userGroup){
        if (!StringUtils.isNotEmpty(userGroup)){
            return error("请选择要添加的成员！");
        }
        return toAjax(groupService.installUserInGroup(groupId, userGroup));
    }



    // 将用户从该小组移除
    @DeleteMapping("/removeUserOnGroup/{groupId}")
    public AjaxResult removeUserOnGroup(@PathVariable Long groupId, @RequestBody Long[] userIds){
        if (!StringUtils.isNotEmpty(userIds)){
            return error("请选择要删除的成员！");
        }
        return toAjax(groupService.deleteUserInGroup(groupId, userIds));
    }



}
